package onlyviewer.display.java.model;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;

public class Filters {
    static {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }
    //复古滤镜
    public Mat Retro(Mat img){
        int height = img.height();
        int width = img.width();
        for(int i = 0; i < height; i++) {
            for(int j = 0; j < width; j++) {
                double b = img.get(i, j)[0];
                double g = img.get(i, j)[1];
                double r = img.get(i, j)[2];
                // 计算新的图像中的RGB值
                // 约束图像像素值，防止溢出, 变换后的RGB值要约束在0 ~ 255 之间
                int B = (int) (0.273 * r + 0.535 * g + 0.131 * b);
                int G = (int) (0.347 * r + 0.683 * g + 0.167 * b);
                int R = (int) (0.395 * r + 0.763 * g + 0.188 * b);
                // 照片变旧只需对图片的颜色空间进行处理
                img.put(i, j, Math.max(0, Math.min(B, 255)), Math.max(0, Math.min(G, 255)), Math.max(0, Math.min(R, 255)));
            }
        }
        return img;
    }
    //你可以仿照复古滤镜，进行更新
}
